package com.itic.system.market.category.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.system.market.category.persistence.dao.CategoryDao;
import com.itic.system.market.category.persistence.model.Category;
import com.itic.system.market.category.persistence.model.CategoryExample;


@Service
@Transactional
public class CategoryService
     extends CrudService<CategoryDao,Category,CategoryExample> {
    @Autowired
    private CategoryDao categoryDao;

	public Category getByCode(String categoryCode) {
		CategoryExample example = new CategoryExample();
		com.itic.system.market.category.persistence.model.CategoryExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andCategoryCodeEqualTo(categoryCode);
		List<Category> list = categoryDao.selectByExample(example);
		if( !list.isEmpty() ){
			return list.get(0);
		}else{
			return null;
		}
	}

	public String getCode() {
		CategoryExample example = new CategoryExample();
		com.itic.system.market.category.persistence.model.CategoryExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		List<Category> list = categoryDao.selectByExample(example);
		if( list.size() >= 0 && list.size()<=9  ){
			return "100"+list.size();
		}else
		if( list.size() >= 10 && list.size()<=99 ){
			return "10"+list.size();
		}else{
			return "1000";
		}
	}


}